package com.ljpz.web.handler.mq;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ljpz.common.service.RedisService;
import com.ljpz.web.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;

/**
 * Created by liujunchen on 2017/1/2.
 */
public class ItemMQHandler {
    @Autowired
    private RedisService redisService;
    private  static  final ObjectMapper MAPPER=new ObjectMapper()  ;
    /**
     *
     *删除缓存的商品数据，完成数据同步
     * @param msg
     */
    public  void execute(String msg ){
        try {
            JsonNode jsonNode=MAPPER.readTree(msg)  ;
            Long itemId= jsonNode.get("itemId").asLong();
            String key= ItemService.REDIS_KEYS+itemId;
            this.redisService.del(key)   ;
        } catch (Exception  e) {
            e.printStackTrace();
        }

    }
}
